<?php

/**
 * Project form.
 *
 * @package    form
 * @subpackage Project
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $
 */
class ProjectForm extends BaseProjectForm
{
  public function configure()
  {
    unset(
      $this['created_at'], $this['updated_at'],
      $this['lft'], $this['rgt'], $this['level']
    );
    
    $this->projects = Doctrine::getTable('Project');
    
    $this->widgetSchema['parent_id'] = new sfWidgetFormChoice(array(
      'multiple' => false, 'expanded' => false,
      'choices' => $this->getProjectsArr()
    ));
    
    $this->validatorSchema['parent_id'] = new sfValidatorChoice(array(
      'choices' => array_keys($this->getProjectsArr())
    ));
    
    $this->widgetSchema->setLabel('parent_id', 'Parent project');
  }
  
  public function getProjectsArr()
  {
    $proectsArr = array();
    
    foreach($this->projects->getTree()->fetchTree() as $project)
    {
      $projectsArr[$project['id']] = str_repeat('&nbsp;&nbsp;', $project['level']).($project['level'] == 0 ? '' : '|-').$project['name'];
    }
    
    return $projectsArr;
  }
}
